const USER_TOKEN = 'USER_TOKEN'
const CHANNEL_KEY = 'CHANNEL_KEY'
// 获取token
type Token = { token: string; refresh_token: string }
export const setItem = (token: Token | {}) => {
  window.localStorage.setItem(USER_TOKEN, JSON.stringify(token))
}

// 存储token
export const getItem = (): Token =>
  JSON.parse(localStorage.getItem(USER_TOKEN) || '{}')

// 删除token
export const removeItem = () => localStorage.removeItem(USER_TOKEN)

// 保存channel
type Channels = { id: number; name: string }[]
export const setLocalChannels = (channels: Channels) => {
  window.localStorage.setItem(CHANNEL_KEY, JSON.stringify(channels))
}

// 获取channel
export const getLocalChannels = () => {
  return JSON.parse(localStorage.getItem(CHANNEL_KEY) || '{}')
}

// 删除channel
export const removeLocalChannels = () => localStorage.removeItem(CHANNEL_KEY)
